//
//  HTextViewCell.m
//  quxiangtao
//
//  Created by HHuajiang on 2018/12/18.
//  Copyright © 2018 shanhaijin. All rights reserved.
//

#import "HTextViewCell.h"

@implementation HTextViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        UILabel *leftTitleLabel = [[UILabel alloc] init];
        leftTitleLabel.text = @"分享文案";
        leftTitleLabel.font = Font(30);
        leftTitleLabel.textColor = Color333333;
        [self.contentView addSubview:leftTitleLabel];
        [leftTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(Margin);
            make.top.mas_equalTo(Margin);
        }];
        
        UIButton *copywritingButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [copywritingButton setImage:[UIImage imageNamed:@"复制"] forState:UIControlStateNormal];
        [copywritingButton setTitle:@" 仅复制分享文案" forState:UIControlStateNormal];
        copywritingButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [copywritingButton setTitleColor:Colorff0000 forState:UIControlStateNormal];
        copywritingButton.titleLabel.font = Font(30);
        [self.contentView addSubview:copywritingButton];
        [copywritingButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_equalTo(-Margin);
            make.centerY.equalTo(leftTitleLabel.mas_centerY);
            make.size.mas_equalTo(CGSizeMake(190, 20));
        }];
        [copywritingButton addTarget:self action:@selector(copywritingButtonClick) forControlEvents:UIControlEventTouchUpInside];
        
        UIView *copywritingView = [[UIView alloc] init];
        copywritingView.backgroundColor = Colordddddd;
        [self.contentView addSubview:copywritingView];
        [copywritingView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(Margin);
            make.right.mas_equalTo(-Margin);
            make.top.equalTo(leftTitleLabel.mas_bottom).offset(2*Margin);
            make.bottom.mas_equalTo(0);
        }];
        
        MKViewBorderRadius(copywritingView, Margin, 0, WhiteColor);
        
        UILabel *copywritingLabel = [[UILabel alloc] init];
        copywritingLabel.textColor = Color999999;
        copywritingLabel.numberOfLines = 0;
        copywritingLabel.font = Font(30);
        [copywritingView addSubview:copywritingLabel];
        [copywritingLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.top.mas_equalTo(Margin);
            make.right.mas_equalTo(-Margin);
        }];
        self.copywritingLabel = copywritingLabel;
    }
    return self;
}

- (void)setModel:(TbGoodsListModel *)model WithItemUrl:(nonnull NSString *)item_url{
    self.llmodel = model;
    self.copywritingLabel.text = [NSString stringWithFormat:@"%@\n【在售价】%@\n【券后价】%@\n【淘口令】\n%@" , model.title, model.goods_price, model.zk_final_price, model.model];
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.copywritingLabel.text];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:5];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, self.copywritingLabel.text.length)];
    self.copywritingLabel.attributedText = attributedString;
    [self.copywritingLabel sizeToFit];
    
}

- (void)copywritingButtonClick {
    UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
    pasteboard.string = [NSString stringWithFormat:@"%@\n---------------------\n復·制这段描述%@后咑閞👉手机淘宝👈查看",self.copywritingLabel.text,self.llmodel.model];
    [[KYAlertView sharedInstance] showAlertViewWithMessage:@"复制文案成功"];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

@end
